package api.manager;

import android.content.Context;
import android.support.annotation.NonNull;

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.util.List;

import api.base.bean.BasicResponse;
import api.base.observer.DefaultNoParamsObserver;
import api.base.observer.DefaultObserver;
import api.http.MeiZi.api.IMeizi;
import api.http.MeiZi.api.MeiziImpl;
import api.http.MeiZi.bean.MeiZi;
import api.http.file.api.IUpdataFile;
import api.http.file.api.UpdataFileImpl;
import api.http.file.bean.UpLoatBean;
import api.http.news.api.INews;
import api.http.news.api.NewsImpl;
import api.http.news.bean.News;
import api.http.object.api.IObject;
import api.http.object.api.ObjectImpl;
import api.http.object.bean.ObjectBean;
import api.http.object.bean.Student;
import api.http.sites.api.ISites;
import api.http.sites.api.SitesImpl;
import api.http.sites.bean.Site;
import api.utils.Utils;


/**
 * Created by Administrator on 2018-01-11.
 */

public class Manager implements IMeizi,IObject<Student>,IUpdataFile<String>,INews,ISites{

    static volatile Manager mManager;

    private static MeiziImpl mMeizi;
    private static ObjectImpl mObject;
    private static UpdataFileImpl sUpdataFile;
    private static NewsImpl sNews;
    private static SitesImpl sSites;

    private Manager() {


    }

    public static Manager getInstance() {
        if (mManager == null) {
            synchronized (Manager.class) {
                if (mManager == null) {
                    mManager = new Manager();
                }
            }
        }
        return mManager;
    }

    public static Manager init(@NonNull Context context) {
//        initLogger(context);
        //设置全局的Context

        Utils.setContext(context);
//        Logger.i("初始化 diycode");
//
//        OAuth.client_id = client_id;
//        OAuth.client_secret = client_secret;

        initImplement(context);

        return getInstance();
    }

    private static void initImplement(Context context) {

        mObject = new ObjectImpl();
        mMeizi = new MeiziImpl();
        sUpdataFile = new UpdataFileImpl();
        sNews = new NewsImpl();
        sSites = new SitesImpl();
    }
    @Override
    public void getMeizi(RxAppCompatActivity context, DefaultObserver<BasicResponse<List<MeiZi>>> observer) {
        mMeizi.getMeizi(context,observer);
    }

    @Override
    public void addObject(RxAppCompatActivity context, Student student, DefaultObserver<BasicResponse<ObjectBean>> observer) {
        mObject.addObject(context,student,observer);
    }

    @Override
    public void removeObject(RxAppCompatActivity context, Student student, DefaultObserver<BasicResponse<ObjectBean>> observer) {
        mObject.removeObject(context,student,observer);
    }

    @Override
    public void updataObject(RxAppCompatActivity context, Student student, DefaultObserver<BasicResponse<ObjectBean>> observer) {
        mObject.updataObject(context,student,observer);
    }

    @Override
    public void delObject(RxAppCompatActivity context, Student student, DefaultObserver<BasicResponse<ObjectBean>> observer) {
        mObject.delObject(context,student,observer);
    }

    @Override
    public void upload(RxAppCompatActivity context, String filename, DefaultObserver<BasicResponse<UpLoatBean>> observer) {
        sUpdataFile.upload(context,filename,observer);
    }

    @Override
    public void getNewsList(RxAppCompatActivity context, DefaultNoParamsObserver<List<News>> observer, Integer node_id, Integer offset, Integer limit) {
        sNews.getNewsList(context,observer,node_id,offset,limit);
    }

    @Override
    public void createNews(String title, String address, String node_id) {

    }

    @Override
    public void getCommentNewList(Integer offset, Integer limit) {

    }

    @Override
    public void getNewsTypeList() {

    }

    @Override
    public void getNewsCommentDetails() {

    }

    @Override
    public void updataNewsComment(String body) {

    }

    @Override
    public void delNews() {

    }

    @Override
    public void getSiteList(RxAppCompatActivity context, DefaultNoParamsObserver<List<Site>> observer) {
        sSites.getSiteList(context,observer);
    }
}